/*
 * Copyright (c) 2009. Silenus Consultoria, S.L.
 */
package es.silenus.detecta.model;

/**
 * A knowledge unit form question answer. Data is only 0/1 Persistent class, read-write.
 *
 * @author <a href="mailto:malonso@silenus-consultoria.es">Mariano Alonso</a>
 *
 * @since 22-mar-2009 11:04:04
 */
public class SurveyUnitAnswer implements java.io.Serializable {
	/**
	 * The identifier.
	 */
	private SurveyUnitAnswerId id;

	/**
	 * The type of training preferences (remote, at office... etc)
	 */
	private TrainingPreference preference;

	/**
	 * Flag to signal when a unit answer has been covered.
	 */
	private boolean covered;

/**
   * Constructor.
   */
	public SurveyUnitAnswer() {
		id = new SurveyUnitAnswerId();
		preference = TrainingPreference.PRESENTIAL;
		covered = false;
	}

	/**
	 * Retrieves the identifier.
	 *
	 * @return the identifier.
	 */
	public SurveyUnitAnswerId getId() {
		return this.id;
	}

	/**
	 * Sets the identifier.
	 *
	 * @param id the identifier.
	 */
	public void setId(final SurveyUnitAnswerId id) {
		this.id = id;
	}

	/**
	 * Retrieves the training preference.
	 *
	 * @return the training preference.
	 */
	public TrainingPreference getPreference() {
		return this.preference;
	}

	/**
	 * Sets the training preference.
	 *
	 * @param preference the training preference.
	 */
	public void setPreference(final TrainingPreference preference) {
		this.preference = preference;
	}

	/**
	 * Return the covered flag.
	 *
	 * @return the covered flag.
	 */
	public boolean isCovered() {
		return covered;
	}

	/**
	 * Sets the covered flag.
	 *
	 * @param covered the covered flag.
	 */
	public void setCovered(boolean covered) {
		this.covered = covered;
	}

	/**
	 * Retrieves the header.
	 *
	 * @return the header.
	 */
	public SurveyAnswerHeader getHeader() {
		return getId().getHeader();
	}

	/**
	 * Sets the header.
	 *
	 * @param header the header.
	 */
	public void setHeader(final SurveyAnswerHeader header) {
		getId().setHeader(header);
	}

	/**
	 * Retrieves the question.
	 *
	 * @return the question.
	 */
	public Question getQuestion() {
		return getId().getQuestion();
	}

	/**
	 * Sets the question.
	 *
	 * @param question the question.
	 */
	public void setQuestion(final Question question) {
		getId().setQuestion(question);
	}

	/**
	 * Checks if objects are equal.
	 *
	 * @param o other object.
	 *
	 * @return true if equal, false otherwise.
	 */
	@Override
	public boolean equals(Object o) {
		if(this == o) {
			return true;
		}

		if(!(o instanceof SurveyUnitAnswer)) {
			return false;
		}

		SurveyUnitAnswer that = (SurveyUnitAnswer)o;

		if((getId() != null) ? (!getId().equals(that.getId())) : (that.getId() != null)) {
			return false;
		}

		return true;
	}

	/**
	 * Calculates the hash of this instance.
	 *
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		return (getId() != null) ? getId().hashCode() : 0;
	}

	/**
	 * Stringifies this instance.
	 *
	 * @return the string representation.
	 */
	@Override
	public String toString() {
		final StringBuilder sb = new StringBuilder();

		sb.append("SurveyUnitAnswer");
		sb.append("{id=").append(getId());
		sb.append('}');

		return sb.toString();
	}
}
